package com.cyw.search.entity.videos;

import cn.easyes.annotation.IndexField;
import cn.easyes.annotation.IndexId;
import cn.easyes.annotation.IndexName;
import cn.easyes.common.constants.Analyzer;
import cn.easyes.common.enums.FieldType;
import cn.easyes.common.enums.IdType;
import cn.easyes.common.params.JoinField;
import com.cyw.common.core.domain.entity.SysUser;
import com.cyw.common.helper.LoginHelper;
import com.cyw.search.vo.CreatorVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Author: 二叔
 * @Date: 2022/11/10/22:41
 */
@Data
@ApiModel("短视频实体类")
@IndexName(value = "videos_document",shardsNum = 3,replicasNum = 2,childClass = VideosComment.class)
public class Videos implements Serializable {
    @ApiModelProperty("短视频id")
    @IndexId(type = IdType.NONE)
    private String id;

    @ApiModelProperty("发布者id")
    @IndexField(fieldType = FieldType.LONG)
    private Long userId;

    @ApiModelProperty("发布者")
    @IndexField(fieldType = FieldType.OBJECT)
    private CreatorVo creatorVo;

    @ApiModelProperty("用户(无用)")
    @IndexField(fieldType = FieldType.NESTED, nestedClass = CreatorVo.class)
    private List<CreatorVo> creatorVos;

    @ApiModelProperty("短视频描述")
    @IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_MAX_WORD)
    private String description;

    @ApiModelProperty("短视频地址")
    @IndexField(fieldType = FieldType.KEYWORD)
    private String videosUrl;

    @ApiModelProperty("短视频点赞量")
    @IndexField(fieldType = FieldType.INTEGER)
    private Integer likeCount = 0;

    @ApiModelProperty("短视频点赞人")
    @IndexField(fieldType = FieldType.KEYWORD)
    private Set<Long> likeUserSet = new HashSet<>();

    @ApiModelProperty("得分")
    @IndexField(fieldType = FieldType.KEYWORD)
    private String score;

    @ApiModelProperty("短视频距离我")
    @IndexField(exist = false)
    private String distance;

    @ApiModelProperty("创建时间")
    @IndexField(fieldType = FieldType.DATE, dateFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
    private String createTime;

    @ApiModelProperty("发布地点经纬度坐标:40.13933715136454,116.63441990026217")
    @IndexField(fieldType = FieldType.GEO_POINT)
    private String location;

    @ApiModelProperty("短视频评论")
    @IndexField(fieldType = FieldType.JOIN, parentName = "videos_document", childName = "videos_comment")
    private JoinField joinField;

    public static Videos initPublish(String description,String videosUrl,String geoPoint,SysUser sysUser){
        Videos videos = new Videos();
        videos.setDescription(description);
        videos.setVideosUrl(videosUrl);
        videos.setLocation(geoPoint);
        videos.setUserId(LoginHelper.getUserId());
        CreatorVo creatorVo = new CreatorVo();
        BeanUtils.copyProperties(sysUser,creatorVo);
        videos.setCreatorVo(creatorVo);
        return videos;
    }

}
